import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/lifeCircle/data/api/life_topic_list_api.dart';
import 'package:casdon/modules/lifeCircle/data/repository/life_repository.dart';

class LifeTopicSearchUsecase {
  final LifeRepository _repository;

  const LifeTopicSearchUsecase(this._repository);

  Future<ResponseLifeTopicListApi> execute({
    required String searchText,
    required int pageNum,
    required int pageSize,
  }) async {
    try {
      var ret = await _repository.searchTopicList(
        searchText: searchText,
        pageNum: pageNum,
        pageSize: pageSize,
      );
      ret ??= ResponseLifeTopicListApi(0, []);
      return ret;
    } on BusinessException {
      rethrow;
    } catch (e) {
      Log.e("LifeTopicSearchUsecase 失败", e.toString(), StackTrace.current);
      throw Exception("LifeTopicSearchUsecase 失败");
    }
  }
}
